var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.C2API = void 0);
var t = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  r = require("../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../@babel/runtime/helpers/classCallCheck"),
  a = require("../../@babel/runtime/helpers/createClass"),
  u = e(require("../globalConfig/globalConfig")),
  s = require("../utils/queryString"),
  i = require("../common/wxENV"),
  c = (function () {
    function e() {
      n(this, e);
    }
    var c, o, l, h, f, p;
    return (
      a(e, null, [
        {
          key: "fullUrl",
          value: function (e) {
            return ""
              .concat(u.default.apiHost)
              .concat(u.default.apiPrefix)
              .concat(e);
          },
        },
        {
          key: "request",
          value: function (e) {
            var t =
                arguments.length > 1 && void 0 !== arguments[1]
                  ? arguments[1]
                  : {},
              r =
                arguments.length > 2 && void 0 !== arguments[2]
                  ? arguments[2]
                  : "GET";
            return new Promise(function (n, a) {
              var u = {
                method: r,
                url: e,
                success: function (e) {
                  n(e.data);
                },
                fail: function (e) {
                  console.error(e), a("error");
                },
              };
              Object.assign(u, t), (0, i.getWxEnv)().request(u);
            });
          },
        },
        {
          key: "ajax",
          value: function (e, t) {
            var r = this,
              n =
                arguments.length > 2 && void 0 !== arguments[2]
                  ? arguments[2]
                  : "GET";
            return new Promise(function (a, u) {
              r.request(r.fullUrl(e), { data: t }, n).then(function (e) {
                0 === e.code ? a(e) : u(e);
              }, u);
            });
          },
        },
        {
          key: "post",
          value: function (e, t) {
            return this.ajax(e, t, "POST");
          },
        },
        {
          key: "get",
          value: function (e) {
            return this.ajax(e);
          },
        },
        {
          key: "updateUserInfo",
          value:
            ((p = r(
              t().mark(function e(r, n) {
                return t().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          return e.abrupt(
                            "return",
                            this.post("/user/user-info/".concat(r), n),
                          );
                        case 1:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e, t) {
              return p.apply(this, arguments);
            }),
        },
        {
          key: "checkUVC",
          value: function (e) {
            e.data ? (this.slUVC = e.data.uvCode) : (this.slUVC = null);
          },
        },
        {
          key: "wxAuth",
          value:
            ((f = r(
              t().mark(function e(r, n) {
                var a;
                return t().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          return (
                            (e.next = 2),
                            this.post("/user/wx-auth", { appId: r, jsCode: n })
                          );
                        case 2:
                          return (
                            (a = e.sent),
                            this.checkUVC(a),
                            e.abrupt("return", a)
                          );
                        case 5:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e, t) {
              return f.apply(this, arguments);
            }),
        },
        {
          key: "thirdAuth",
          value:
            ((h = r(
              t().mark(function e(r) {
                var n;
                return t().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          return (e.next = 2), this.post("/user/third-auth", r);
                        case 2:
                          return (
                            (n = e.sent),
                            this.checkUVC(n),
                            e.abrupt("return", n)
                          );
                        case 5:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e) {
              return h.apply(this, arguments);
            }),
        },
        {
          key: "getUVC",
          value:
            ((l = r(
              t().mark(function e(r) {
                var n;
                return t().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          return (
                            (e.prev = 0),
                            (e.next = 3),
                            this.post("/user/uvc/" + r)
                          );
                        case 3:
                          (n = e.sent).data
                            ? (this.slUVC = n.data)
                            : (this.slUVC = null),
                            (e.next = 10);
                          break;
                        case 7:
                          (e.prev = 7),
                            (e.t0 = e.catch(0)),
                            (this.slUVC = null);
                        case 10:
                          return e.abrupt("return", this.slUVC);
                        case 11:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                  [[0, 7]],
                );
              }),
            )),
            function (e) {
              return l.apply(this, arguments);
            }),
        },
        {
          key: "getQrImageUrl",
          value: function (e) {
            return this.fullUrl("/qr-code/image".concat((0, s.queryString)(e)));
          },
        },
        {
          key: "getAoAMac",
          value:
            ((o = r(
              t().mark(function e(r, n) {
                var a;
                return t().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          return (
                            (e.next = 2),
                            this.get(
                              "/store/info?projectCode="
                                .concat(r, "&userId=")
                                .concat(n, "&key=$AOA_UID"),
                            )
                          );
                        case 2:
                          return (
                            (a = e.sent),
                            e.abrupt(
                              "return",
                              parseInt(a.data.value).toString(16),
                            )
                          );
                        case 4:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e, t) {
              return o.apply(this, arguments);
            }),
        },
        {
          key: "getConfigWithCache",
          value:
            ((c = r(
              t().mark(function e(r) {
                var n,
                  a,
                  u,
                  s = arguments;
                return t().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          if (
                            ((n = s.length > 1 && void 0 !== s[1] && s[1]),
                            this._cacheConfig[r] && !n)
                          ) {
                            e.next = 10;
                            break;
                          }
                          return (
                            (e.next = 4),
                            this.get("/basic/getConfig?projectCode=".concat(r))
                          );
                        case 4:
                          if (0 === (a = e.sent).code) {
                            e.next = 7;
                            break;
                          }
                          throw new Error(
                            "get config error:" + JSON.stringify(a),
                          );
                        case 7:
                          (u = {}),
                            a.data.configs.forEach(function (e) {
                              var t = e.propertyCode,
                                r = e.content,
                                n = JSON.parse(r);
                              "customConfig" !== t &&
                                ((n = {})[t] = JSON.parse(r)),
                                Object.assign(u, n);
                            }),
                            (this._cacheConfig[r] = u);
                        case 10:
                          return e.abrupt("return", this._cacheConfig[r]);
                        case 11:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e) {
              return c.apply(this, arguments);
            }),
        },
      ]),
      e
    );
  })();
(exports.C2API = c), (c._cacheConfig = {}), (c.slUVC = null);
